//
//  copy_initialization.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/7.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef copy_initialization_hpp
#define copy_initialization_hpp

#include <stdio.h>
#include <iostream>
#include <cassert>

class Fraction4
{
private:
    int m_numerator;
    int m_denominator;
    
public:
    // Default constructor
    Fraction4(int numerator=0, int denominator=1) :
    m_numerator(numerator), m_denominator(denominator)
    {
        assert(denominator != 0);
    }
    
    // Copy constructor
    Fraction4(const Fraction4 &copy) :
    m_numerator(copy.m_numerator), m_denominator(copy.m_denominator)
    {
        // no need to check for a denominator of 0 here since copy must already be a valid Fraction
        std::cout << "Copy constructor called\n"; // just to prove it works
    }
    
    friend std::ostream& operator<<(std::ostream& out, const Fraction4 &f1);
    int getNumerator() { return m_numerator; }
    void setNumerator(int numerator) { m_numerator = numerator; }
};

Fraction4 makeNegative(Fraction4 f);



/*
 
 std::cout << makeNegative(6);
 //当调用makeNegative(6)时，由于6不是Fraction4类型，所以会尝试将6转换为Fraction4类型,它通过使用Fraction（int，int）构造函数复制初始化makeNegative（）参数f来完成此操作。
 
 */


#endif /* copy_initialization_hpp */
